.TH std::get(std::array) 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::get(std::array) \- std::get(std::array)

.SH Synopsis
   Defined in header <array>
   template< std::size_t I, class T, std::size_t N >    \fB(1)\fP \fI(since C++11)\fP
   T& get( std::array<T,N>& a ) noexcept;                   (constexpr since C++14)
   template< std::size_t I, class T, std::size_t N >    \fB(2)\fP \fI(since C++11)\fP
   T&& get( std::array<T,N>&& a ) noexcept;                 (constexpr since C++14)
   template< std::size_t I, class T, std::size_t N >    \fB(3)\fP \fI(since C++11)\fP
   const T& get( const std::array<T,N>& a ) noexcept;       (constexpr since C++14)
   template< std::size_t I, class T, std::size_t N >    \fB(4)\fP \fI(since C++11)\fP
   const T&& get( const std::array<T,N>&& a ) noexcept;     (constexpr since C++14)

   Extracts the I^th element from the array using tuple-like interface.

   I must be an integer value in range [0, N). This is enforced at compile time as
   opposed to at() or operator[].

.SH Parameters

   a - array whose contents to extract

.SH Return value

   A reference to the I^th element of a.

.SH Complexity

   Constant.

.SH Example


// Run this code

 #include <array>
 #include <iostream>

 constexpr std::array v{1, 2, 3};
 static_assert(get<0>(v) == 1 && get<1>(v) == 2 && get<2>(v) == 3);

 int main()
 {
     std::array<int, 3> a;

     // set values:
     get<0>(a) = 1, get<1>(a) = 2, get<2>(a) = 3;

     // get values:
     std::cout << '(' << get<0>(a) << ',' << get<1>(a) << ',' << get<2>(a) << ")\\n";
 }

.SH Output:

 (1,2,3)

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to          Behavior as published              Correct behavior
   LWG 2485 C++11      there are no overloads for const array&& the overloads are added

.SH See also

   Structured binding \fI(C++17)\fP binds the specified names to sub-objects or tuple
                              elements of the initializer
   operator[]                 access specified element
                              \fI(public member function)\fP
   at                         access specified element with bounds checking
                              \fI(public member function)\fP
   get(std::tuple)            tuple accesses specified element
   \fI(C++11)\fP                    \fI(function template)\fP
   get(std::pair)             accesses an element of a pair
   \fI(C++11)\fP                    \fI(function template)\fP
   get(std::variant)          reads the value of the variant given the index or the
   \fI(C++17)\fP                    type (if the type is unique), throws on error
                              \fI(function template)\fP
   get(std::ranges::subrange) obtains iterator or sentinel from a std::ranges::subrange
   (C++20)                    \fI(function template)\fP
